package com.atguigu.ssyx.home.service.impl;


import com.atguigu.ssyx.client.product.ProductFeignClient;
import com.atguigu.ssyx.client.search.SearchFeignClient;
import com.atguigu.ssyx.client.user.UserFeginClient;
import com.atguigu.ssyx.home.service.HomeService;
import com.atguigu.ssyx.model.product.Category;
import com.atguigu.ssyx.model.product.SkuInfo;
import com.atguigu.ssyx.model.search.SkuEs;
import com.atguigu.ssyx.vo.user.LeaderAddressVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class HomeServiceImpl implements HomeService {
    private final UserFeginClient userFeginClient;
    private final ProductFeignClient productFeignClient;

    private final SearchFeignClient searchFeignClient;


    @Override
    public Map<String, Object> home(Long userId) {

        HashMap<String, Object> map = new HashMap<>();
        //1 根据用户Id查询当前登录用户的提货地址信息
        //远程调用service-user模块接口获取需要的数据
        LeaderAddressVo leaderAddressVo = userFeginClient.getUserAddressByUserId(userId);
       if(leaderAddressVo != null){
           map.put("leaderAddressVo", leaderAddressVo);
       }

        //2.获取所有的分类
        //远程调用service-product模块接口获取需要的数据
        List<Category> allCategoryList = productFeignClient.findAllCategoryList();
        map.put("allCategoryList", allCategoryList);

        //3.获取新人专享商品
        //远程调用service-product模块接口获取需要的数据
        List<SkuInfo> newPersonSkuInfoList = productFeignClient.findNewPersonSkuInfoList();
        map.put("newPersonSkuInfoList", newPersonSkuInfoList);
        //4.获取爆款商品
        //远程调用service-search模块接口获取需要的数据
        //hotScore 热门评分降序排序
        //得到了爆款的前10个商品
        List<SkuEs> hotSkuList = searchFeignClient.findHotSkuList();
        map.put("hotSkuList", hotSkuList);
        return map;
    }
}
